/*
 * @Descripttion: 
 * @version: 
 * @Author: 刘润泽
 * @Date: 2022-09-05 11:46:18
 * @LastEditors: 刘润泽
 * @LastEditTime: 2023-02-26 22:34:35
 */
package server.business.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import server.business.pojo.MsgText;
import server.business.service.MsgTextService;
import server.business.utils.results.lrz.Result;

@RestController
@RequestMapping("/msgText")
public class MsgTextController {

    @Autowired
    MsgTextService msgTextService;

    // 分页查询
    @GetMapping("/normal/{currentPage}/{pageSize}")
    public Result getPage(@PathVariable int currentPage, @PathVariable int pageSize,
            MsgText msgText) {
        IPage<MsgText> page = msgTextService.getPage(currentPage, pageSize, msgText);
        // 如果当前页码值大于了总页码值，就重新执行查询操作，使用最大页码值作为当前页码值
        if (currentPage > page.getPages()) {
            page = msgTextService.getPage((int) page.getPages(), pageSize, msgText);
        }
        return Result.success(page);
    }

    /**
     * 添加消息记录
     *
     * @param sendTime
     * @param doctorJobNum
     * @param username
     * @param text
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "/normal/addMsgText", method = RequestMethod.POST)
    public Result addMsgText(@RequestBody MsgText msgText) {
        msgTextService.addTextInfo(msgText);
        return Result.success("消息记录添加成功");
    }

    /**
     * 设置消息阅读状态
     *
     * @param id
     * @param doctorJobNum
     * @param state
     * @return
     */
    @RequestMapping(value = "/normal/setReadState", method = RequestMethod.PUT)
    public Result setReadState(@RequestBody MsgText msgText) {
        msgTextService.setReadState(msgText);
        return Result.success("1");
    }

    /**
     * 设置消息删除状态
     *
     * @param id
     * @param doctorJobNum
     * @param isDeleted
     * @return
     */
    @RequestMapping(value = "/normal/setIsDeleted", method = RequestMethod.PUT)
    public Result setIsDeleted(@RequestBody MsgText msgText) {
        msgTextService.setIsDeleted(msgText);
        return Result.success("已删除");
    }

    /**
     * 根据医生工号获取医生0信息条数
     * 
     * @param doctorNum
     * @return
     */
    @GetMapping(value = "/normal/getNoReadNum")
    public Result getNoReadNum(String doctorJobnum) {
        List<MsgText> msgTexts = msgTextService.getTextByDoctorJobnum(doctorJobnum);
        return Result.success(msgTexts.size());
    }

}
